// JavaScript Document

var userLang = (navigator.language) ? navigator.language : navigator.userLanguage; 
userLang = userLang.substring(0, 2);

$(function() {
	insertBar();
	if(document.location.href.indexOf("?r=1") > -1) { return; }
	if(document.referrer.indexOf("bellido") == -1) { redirect(); }
});

function redirect() {
	if(userLang == "es") {
		if (window.location.replace)
			window.location.replace("http://www.bellidolegal.com?r=1");
		else
			window.location.href = "http://www.bellidolegal.com?r=1";
	}
	else {
		if (window.location.replace)
			window.location.replace("http://www.bellidolegal.com/ing/index.html?r=1");
		else
			window.location.href = "http://www.bellidolegal.com/ing/index.html?r=1";	
	}
}
	
function insertBar() {
	var langBar = '<div id="idioma" style="width:100%; font-family:Arial,Helvetica,sans-serif; font-size:13px; background-color:#2855B0; color:white; padding:10px 0;">' +
	'<div class="container_16"><div class="grid_16"></div></div></div>',
	content = '<a href="http://www.bellidolegal.com" style="float:right; margin-right:10px; color:#FFFFFF">Español</a>' + 
	'<a href="http://www.bellidolegal.com/ing/index.html" style="float:right; margin-right:10px; color:#F5B300">English</a>';
	/*content = 'Estás visitando la versión en inglés del sitio ¿Te gustaría ver la versión en español?' +
	'<span style="float:right; cursor:pointer;">No</span><a href="http://www.ncom.pe/bellido/index.html" style="float:right; margin-right:10px; color:#F5B300;">Si</a>';
	if(userLang == "es") {
		content = 'You are visiting the spanish version of the site. Would you like to view the english version?' +
		'<span style="float:right; cursor:pointer;">No</span><a href="http://www.ncom.pe/bellido/ing/index.html" style="float:right; margin-right:10px; color:#F5B300">Yes</a>';
	}*/
	if(document.location.href.indexOf("/ing/") == -1) {
		content = '<a href="http://www.bellidolegal.com" style="float:right; margin-right:10px; color:#F5B300">Español</a>' + 
		'<a href="http://www.bellidolegal.com/ing/index.html" style="float:right; margin-right:10px; color:#FFFFFF">English</a>';
	}
	$("body").prepend(langBar);
	$("#idioma div.grid_16").append(content);
	$("#idioma span").click(function() {
		$("#idioma").slideUp();
	});
}